package com.vue.vuedemo.Controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vue.vuedemo.pojo.Player;
import com.vue.vuedemo.pojo.Team;
import com.vue.vuedemo.service.PlayerService;
import com.vue.vuedemo.service.TeamService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@CrossOrigin(origins = {"http://localhost:8080"}) //当前网站向另一个网站请求数据就是跨域
@Controller
public class PlayerController {

    @Resource
    PlayerService playerService;

    //查询所以游戏信息
    @GetMapping(value="playerFidFindAll")
    public List<Player> fidFindAll(Integer ptname){
        List<Player> playerList = playerService.findAll(ptname);
        return playerList;
    }

    //添加游戏
    @PostMapping(value = "playerAdd")
    @ResponseBody
    public Integer add(@RequestBody Player player){
        System.out.print(player.getPName());
        try {
            playerService.add(player);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }

    public Integer num;
    //删除游戏
    @GetMapping(value = "playerDel")
    public Integer playerDel(Integer pid){
        try {
            playerService.del(pid);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }

    //游戏信息
    @GetMapping(value="playerFindAll")
    public List<Player> FindAll(){
        List<Player> players = playerService.playerFindAll();
        return players;
    }
}
